package qianlong.practice.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import qianlong.practice.entity.User;
import qianlong.practice.service.UserService;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping(value = "/insert",method = RequestMethod.POST)
    public int insert(@RequestBody User user){
        return userService.insert(user);
    }

    @RequestMapping(value = "/update",method = RequestMethod.POST)
    public int update(@RequestBody User user){
        return userService.update(user);
    }

    @RequestMapping(value = "/delete/{id}",method = RequestMethod.GET)
    public int delete(@PathVariable("id") Integer id){
        return userService.delete(id);
    }

    @RequestMapping(value = "/get/{id}",method = RequestMethod.GET)
    public User getOne(@PathVariable("id") Integer id){
        return userService.getOne(id);
    }

    @RequestMapping(value = "/list",method = RequestMethod.GET)
    public List<User> getList(@RequestBody User user){
        return userService.getList(user);
    }
}
